//
//  ViewControllerTouch.m
//  核心动画
//
//  Created by chichaojituan521 on 2017/5/27.
//  Copyright © 2017年 linch. All rights reserved.
//

#import "ViewControllerTouch.h"

@interface ViewControllerTouch ()
{
    UIImageView *imgv;
    CGPoint oldImgc;
    CGPoint newImgc;
}
@end

@implementation ViewControllerTouch

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createUIInterfaceMethod];
    
    
    
    
}
-(void)createUIInterfaceMethod
{
    self.view.backgroundColor = [UIColor lightGrayColor];
    imgv = [[UIImageView alloc]initWithFrame:CGRectMake(50, 50, 30, 30)];
    [self.view addSubview:imgv];
    imgv.image = [UIImage imageNamed:@"btnbtn"];
    imgv.layer.cornerRadius = 15;
    imgv.clipsToBounds = YES;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    
    CGPoint touchPoint = [touch locationInView:self.view];
    
    oldImgc = touchPoint;
}
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    
    CGPoint touchPoint = [touch locationInView:self.view];
    newImgc = touchPoint;
    [self positationToTouchPointWith:newImgc];
}

-(void)positationToTouchPointWith:(CGPoint)point
{
    CGPoint imgvp = imgv.center;
    
    float touchX = newImgc.x - oldImgc.x;
    float touchY = newImgc.y - oldImgc.y;
    float imgvX = imgvp.x + touchX;
    float imgvY = imgvp.y + touchY;
    imgv.center = CGPointMake(imgvX, imgvY);
    oldImgc = point;
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    self.navigationController.navigationBarHidden = YES;
}
@end
